package com.lianxian.xindong.commonsdk.utils.filters;

import android.text.InputFilter;
import android.text.Spanned;

/**
 * @author EDZ
 */
public class CnFilter implements InputFilter {
    public static String BASE_REGEX = "^[ ~！…￥，。《》、？、；：‘“”【】{}（）0-9a-zA-Z!#$%&'()*+,\\-.:;=?@\\[\\\\\\]^_`{|}~\\u4E00-\\u9FA5]+$";

    @Override
    public CharSequence filter(CharSequence source, int start, int end, Spanned dest, int dstart,
                               int dend) {
        if(source.toString().equals("")) {
            return null;
        }

        if(!source.toString().matches(BASE_REGEX)) {
            return "";
        } else {
            return source;
        }
    }
}
